package com.hulk.hyena.project.monitor.loginlog.controller;

import java.util.List;

import com.hulk.hyena.framework.aspectj.lang.enums.BusinessType;
import com.hulk.hyena.framework.web.controller.BaseController;
import com.hulk.hyena.framework.web.domain.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hulk.hyena.common.utils.poi.ExcelUtil;
import com.hulk.hyena.framework.aspectj.lang.annotation.Log;
import com.hulk.hyena.framework.web.page.TableDataInfo;
import com.hulk.hyena.project.monitor.loginlog.domain.LoginRecord;
import com.hulk.hyena.project.monitor.loginlog.service.ILoginRecordService;

/**
 * 系统访问记录
 * 
 * @author hulk
 */
@Controller
@RequestMapping("/monitor/loginlog")
public class LoginlogController extends BaseController
{
    private String prefix = "monitor/loginlog";

    @Autowired
    private ILoginRecordService loginRecordService;

    @RequiresPermissions("monitor:loginlog:view")
    @GetMapping()
    public String loginlog()
    {
        return prefix + "/loginlog";
    }

    @RequiresPermissions("monitor:loginlog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LoginRecord loginlog)
    {
        startPage();
        List<LoginRecord> list = loginRecordService.selectLoginRecordList(loginlog);
        return getDataTable(list);
    }

    @Log(title = "登陆日志", businessType = BusinessType.EXPORT)
    @RequiresPermissions("monitor:loginlog:export")
    @PostMapping("/export")
    @ResponseBody
    public R export(LoginRecord loginlog)
    {
        List<LoginRecord> list = loginRecordService.selectLoginRecordList(loginlog);
        ExcelUtil<LoginRecord> util = new ExcelUtil<LoginRecord>(LoginRecord.class);
        return util.exportExcel(list, "loginlog");
    }

    @RequiresPermissions("monitor:loginlog:remove")
    @Log(title = "登陆日志", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public R remove(String ids)
    {
        return toAjax(loginRecordService.deleteLoginRecordByIds(ids));
    }

    @RequiresPermissions("monitor:loginlog:remove")
    @Log(title = "登陆日志", businessType = BusinessType.CLEAN)
    @PostMapping("/clean")
    @ResponseBody
    public R clean()
    {
        loginRecordService.cleanLogininfor();
        return ok();
    }

}
